You can use the -NSString UTF8String method to get a C string of your NSString. Then, you can use strncpy(DATA. USERNAME, mystring UTF8String, 32) to copy that string into the structure.
You can use the -NSString UTF8String method to get a C string of your NSString. Then, you can use strncpy(DATA. USERNAME, mystring UTF8String, 32); to copy that string into the structure.
Also, if you need USERNAME to be null terminated, add DATA. USERNAME31 = '\0'; – cobbal Dec 23 '10 at 4:59 @cobbal: Good point, missed that. – chpwn Dec 24 '10 at 6:03 @cobbal ehrm, what if the string is not exactly 30 characters in length?
You can get memory crap appended to it. – WTP Jun 16 '11 at 12:09 @WTP If it's a null terminated string you're after, then it doesn't matter what comes after the \0. "Foo\0" is equivalent to "Foo\0randomstuff\0".
– cobbal Jun 16 '11 at 13:35 @cobbal I know that, but you are expecting the string to be exactly 30 bytes (hence DATA. USERNAME31 = '\0';). The crap will be between the end of the string and the \0.
– WTP Jun 16 '11 at 13:38.
You first need to know what encoding is expected. NSString can generate bytes in a wide range of encodings. Then you pass a pointer to the USERNAME array to getCString:maxLength:encoding:.
So, for example, if you want to copy the contents of the NSString myCocoaString as UTF-8 into USERNAME field of a DATA struct called myData, you'd do: BOOL success = myCocoaString getCString:myData. USERNAME maxLength:32 encoding:NSUTF8StringEncoding; NSLog(@"Was %@ to store string contents in USERNAME! ", success?
@"able" : @"not able").
The CString methods of NSString are largely deprecated. Use the UTF8String methods instead. – bbum Dec 23 '10 at 9:28.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.